202407251323 go flag 别在init中使用
202407251323 go flag 别在init中使用
flag.StringVar(&appConfig, "conf", filepath.Join(env.ConfDir(), "app.toml"), "app config file")
flag.Parse()
flag 别在 init 中使用,否则在 go test 的时候会强制校验入参
参考:
go test flag: flag provided but not defined
flag.Parse() is being called before your flag is defined.
You have to make sure that all flag definitions happen before calling flag.Parse(), usually by defining all flags inside init() functions.
本站总访问量次 本站访客数人次 本文总阅读量次